// pages/mch/member/index.js
const App = getApp()

Page({
  data: {
    init: false,
    loading: false,
    triggered: true,
    CustomBar: App.Global.CustomBar,

    page: 1,
    size: 8,
    time: new Date().getTime(),
    pager: {
      now: 1,
      row: 0,
      all: 0,
      fms: 0,
    },
    items: []
  },
  onLoad() {
    this.execLoad(false)
  },
  doPulldown() {
    this.data.page = 1
    this.execLoad(true)
  },
  doReachBottom() {
    if (this.data.page >= this.data.pager.all) {
      return
    }
    this.data.page = this.data.page + 1
    this.execLoad(true)
  },
  // 跳转页面
  toPage(e) {
    console.log(e.currentTarget.dataset,"dsgrehgjjy")
    wx.navigateTo({
      url: e.currentTarget.dataset.uri
    })
  },
  toOrder(e) {
    wx.navigateTo({
      url: `/pages/mch/order/index?mid=${e.currentTarget.dataset.mem.id}`,
    })
  },
  execLoad(pulldown) {
    this.setData({
      loading: true
    })
    App.doPost({
      uri: '/app/merchant/customer/list',
      body: {
        pager: {
          page: this.data.page,
          size: this.data.size,
          time: this.data.time
        },
        query: {
          mob: ''
        }
      },
      fnSucc: resp => {
        if (resp.data.pager.now == 1) {
          this.data.time = resp.data.pager.fms
        }

        this.setData({
          init: true,
          loading: false,
          triggered: false,
          pager: resp.data.pager,
          items: resp.data.pager.now == 1 ? resp.data.items : this.data.items.concat(resp.data.items)
        })

        // 去掉详细时间 只保留日期
        setTimeout(()=>{
          console.log(this.data.items[0].order.begin.substring(0,10),"303030330")
         const Newitem = this.data.items.map(item=>{
            return{
              ...item,
              order:{
                ...item.order,
                begin:item.order?item.order.begin.substring(0,10):'',
                close:item.order?item.order.close.substring(0,10):''
              }
            }

          })
          console.log(Newitem,"909909090")
          this.setData({
            items:Newitem
          })
        },200)
      },
      fnComp: () => {
        if (pulldown) {
          this.triggerEvent('stopPullDown', {})
        }
      }
    })
  }
})